package com.hdu.other.dp.one;

import java.util.Arrays;

public class lc467 {
    class Solution {
        public int findSubstringInWraproundString(String s) {

            // ABC
            // A -> 1
            // B -> 2
            // C -> 3
            // A B C = 3
            // AB BC = 2
            // ABC = 1
            // 3 + 2 + 1
            int len = s.length();
            int[] dp = new int[26];

            dp[s.charAt(0) - 'a'] = 1;
            int curLen = 1;

            for (int i = 1; i < len; i++)
            {
                int cur = s.charAt(i) - 'a';
                int prev = s.charAt(i - 1) - 'a';

                boolean p1 = cur == prev + 1;
                boolean p2 = cur == 0 && prev == 25;

                if (p1 || p2)
                {
                    curLen++;
                }
                else
                {
                    curLen = 1;
                }

                dp[cur] = Math.max(dp[cur], curLen);
            }

            return Arrays.stream(dp).sum();
        }
    }
}
